package com.nt.train.processor;
import com.nt.train.annotation.MyService;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import java.util.Set;
/**
 * https://blog.csdn.net/a718515028/article/details/122720093
 * 自定义MyBeanScanner
 * MyBeanScanner 用来加载指定路径下的Bean和过滤出被@Myservice标记的Beanm
 * @author hlf
 * @version 1.0
 * @date 2022/8/11 15:44
 */
public class MyBeanScanner extends ClassPathBeanDefinitionScanner {

    public MyBeanScanner(BeanDefinitionRegistry registry) {
        super(registry);
    }

    public void registFilters() {
        // 只加载被MyService注解的bean
        addIncludeFilter(new AnnotationTypeFilter(MyService.class));
        //同样的满足任意excludeFilters不会被加载
//      addExcludeFilter(new AnnotationTypeFilter(MyService.class));
    }

    // doScan方法会加载该路径下执行的类型bean
    @Override
    protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
        return super.doScan(basePackages);
    }
}